import {
  processUrl
} from "../utils/index.js"

import {
  isFormData
} from "src/utils/type/type.js"


const uniRequest = config => {
  // 处理请求头
  config.headers = config.headers || {};

  debugger
  return new Promise((resolve, reject) => {
    // 处理URL
    const fullUrl = processUrl(config.baseURL, config.url);


    // 处理 FormData类型的值
    if (isFormData(config.data)) {
      delete config.headers['Content-Type']
    }

    uni.request({
      url: config.url,
      data: config.data,
      header: config.headers,
      method: config.method,
      timeout: config.timeout,
      dataType: config.dataType,
      responseType: config.responseType,
      sslVerify: config.sslVerify,
      success: ({
        data,
        statusCode,
        header
      }) => {
        debugger;
      },
      error: ({
        data,
        statusCode,
        header
      }) => {
        debugger;
      },
      complete: ({
        data,
        statusCode,
        header
      }) => {
        debugger;
      }

    }).then(function onAdapterResolution(response) {
      // 处理请求后的数据
      // Transform response data
      // response.data = transformData(
      //   response.data,
      //   response.headers,
      //   config.transformResponse
      // );

      return response;
    }, function onAdapterRejection(reason) {
      // if (!isCancel(reason)) {
      //   throwIfCancellationRequested(config);

      //   // Transform response data
      //   if (reason && reason.response) {
      //     reason.response.data = transformData(
      //       reason.response.data,
      //       reason.response.headers,
      //       config.transformResponse
      //     );
      //   }
      // }

      return Promise.reject(reason);
    })
  })
}
export default uniRequest;
